//
//  WithdrawViewController.m
//  YongChuanTradingArea
//
//  Created by Vivian on 2017/9/12.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "WithdrawViewController.h"

@interface WithdrawViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *wayImgView;
@property (weak, nonatomic) IBOutlet UILabel *wayLabel;
@property (weak, nonatomic) IBOutlet UITextField *amtTF;
@property (weak, nonatomic) IBOutlet UILabel *finalLabel;
@property (weak, nonatomic) IBOutlet UILabel *costLabel;

@end

@implementation WithdrawViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"提现";
    self.view.backgroundColor = kBgColor;
    self.type = self.type;
    self.amtTF.placeholder = [NSString stringWithFormat:@"可转出余额%@元",self.amt?:@"0.00"];
    // Do any additional setup after loading the view from its nib.
}

- (void)setType:(WithdrawType)type{
    _type = type;
    if (_type == WithdrawTypeBank) {
        self.wayImgView.image = [UIImage imageNamed:@"ic_unionpay"];
        self.wayLabel.text = @"提现到银行卡";
    }
    if (_type == WithdrawTypeWechat) {
        self.wayImgView.image = [UIImage imageNamed:@"ic_wechat_pay"];
        self.wayLabel.text = @"提现到微信";
    }
    if (_type == WithdrawTypeAliPay) {
        self.wayImgView.image = [UIImage imageNamed:@"ic_alipay"];
        self.wayLabel.text = @"提现到支付宝";
    }
}

#pragma mark - btn clicked
- (IBAction)allBtnAction:(UIButton *)sender {
    self.amtTF.text = self.amt;
    self.finalLabel.text = [NSString stringWithFormat:@"￥%@",self.amt];
}


- (IBAction)confirmBtnActiion:(UIButton *)sender {
    CGFloat amt = [self.amtTF.text floatValue];
    if (amt < 10) {
        [MBProgressHUD showError:@"提现最小额度￥10"];
        return;
    }
    [self withdrawWithAmt:self.amtTF.text];
}

#pragma mark - request data
- (void)withdrawWithAmt:(NSString *)amt{
    [LBNetworkingInstance requestGET:userWallet parameters:@{@"memberId":[LBUserManage defaultManager].userModel.ID?:@"", @"type":[NSNumber numberWithInteger:self.type + 1],@"moneyDecimal":amt?:@""} showHUD:YES success:^(id responseObject, NSInteger code, NSString *message) {
        if (code == YCNetworkingStatusCodeSuccess){
            [MBProgressHUD showSuccess:@"提现成功！"];
            [UIViewController toHome];
        }
    } failure:^(NSError *err) {
        [MBProgressHUD showSuccess:@"提现失败！"];
    }];
}

#pragma mark - textfiled
- (IBAction)textFieldDidChange:(UITextField *)sender {
    CGFloat amt = [sender.text floatValue];
    CGFloat totalAmt = [self.amt floatValue];
    if (amt > totalAmt) {
        [MBProgressHUD showError:@"超过总金额，请重新输入"];
        sender.text = @"";
        self.finalLabel.text = @"￥0.00";
        [sender resignFirstResponder];
    }else{
        self.finalLabel.text = [NSString stringWithFormat:@"￥%.2f",amt];
    }
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    
    return UIStatusBarStyleDefault;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

